import { v4 as uuid } from 'uuid'
import { StdBlock } from './block'

export class StdPage {
  constructor({ pageId, pageNo, pageType = 'cover', pageLayout = 'portrait', blockList = [], pageSetting = {},pageName ,variableId}) {
    // 第几页
    if (pageNo) this.pageNo = pageNo
    // 页面id
    this.pageId = pageId || uuid()
    // 页面类型, 枚举参考page-type
    this.pageType = pageType
    // 页面布局 landscape:横向 portrait:纵向
    this.pageLayout = ['landscape', 'portrait'].includes(pageLayout) ? pageLayout : 'portrait'
    // 按页面布局从上到下的顺序进行数据聚合；默认一类数据是一个block
    this.blockList = blockList.map((i) => new StdBlock(i))
    this.variableId = variableId;
    // 如果横向尺寸会相应变化
    if (pageLayout === 'landscape') {
      pageSetting.pageWidth = 297
      pageSetting.pageHeight = 210
      pageSetting.pageLeft = 10
      pageSetting.pageTop = 15
    }
    // 页面配置
    this.pageSetting = new StdPageSetting(pageSetting)
    // 页面名称
    this.pageName = pageName;
  }
}

class StdPageSetting {
  constructor(params) {
    const { pageWidth = 210, pageHeight = 297, pageTop = 10, pageBottom = 10, pageLeft = 15, pageRight = 10 } = params
    const { pageGutter = 15 } = params
    // 页面宽度-单位mm
    this.pageWidth = pageWidth
    // 页面高度-单位mm
    this.pageHeight = pageHeight
    // 距离当前页顶部的距离-单位mm
    this.pageTop = pageTop
    // 距离当前页底部的距离-单位mm
    this.pageBottom = pageBottom
    // 距离当前页左侧的距离-单位mm
    this.pageLeft = pageLeft
    // 距离当前页右侧的距离-单位mm
    this.pageRight = pageRight
    // 左侧的装订线
    this.pageGutter = pageGutter
  }
}
